package models;

public class BeanProfile {
	
	private String nombre = "";
	private String apellidos = "";
	private String sexo = "";
	private String day = "";
	private String month = "";
	private String year = "";
	private String llocnaix ="";
	private String hobbies ="";
	private String password ="";
	private int[] error = {0,0,0,0,0,0,0,0,0}; 
	
	
	public BeanProfile(){

	}
	
	public BeanProfile(String password, String nombre, String apellidos, String sexo, String day, String month, String year, String llocnaix, String hobbies){

		this.nombre = nombre;
		this.apellidos = apellidos;
		this.day = day;
		this.month = month;
		this.year = year;
		this.sexo = sexo;
		this.llocnaix = llocnaix;
		this.hobbies = hobbies;
		this.password = password;
	}
	
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getNombre() {
		return nombre;
	}
	public void setNombre(String nombre) {
		this.nombre = nombre;
	}
	public String getApellidos() {
		return apellidos;
	}
	public void setApellidos(String apellidos) {
		this.apellidos = apellidos;
	}
	public String getSexo() {
		return sexo;
	}
	public void setSexo(String sexo) {
		this.sexo = sexo;
	}

	public String getDay() {
		return day;
	}

	public void setDay(String day) {
		this.day = day;
		if(!isDateValid()){error[7] = 1;}
	}

	public String getMonth() {
		return month;
	}

	public void setMonth(String month) {
		this.month = month;
		if(!isDateValid()){error[8] = 1;}
	}

	public String getYear() {
		return year;
	}

	public void setYear(String year) {
		this.year = year;
	}

	public String getLlocnaix() {
		return llocnaix;
	}
	public void setLlocnaix(String llocnaix) {
		this.llocnaix = llocnaix;
	}
	public String getHobbies() {
		return hobbies;
	}
	public void setHobbies(String hobbies) {
		this.hobbies = hobbies;
	}
	
	public boolean isComplete() {
	    return(hasValue(getNombre()) &&
	           hasValue(getSexo()) &&
	           hasValue(getDay()) &&
	           hasValue(getYear()) &&
	           hasValue(getMonth()) &&
	           hasValue(getApellidos()) &&
	           hasValue(getPassword()) &&
	           isDateValid());
	}
	
	private boolean hasValue(String val) {
		return((val != null) && (!val.equals("")));
	}
	
	private boolean isDateValid(){
		boolean valid = true;
		if(!day.equals("") && !month.equals(""))
		{
			if(month.equals("2")){
				if(Integer.parseInt(day) > 28){valid = false;}
			}
			if(month.equals("4") || month.equals("6") || month.equals("9") || month.equals("11")){
				if(Integer.parseInt(day) > 30){valid = false;}
			}	
		}
		return valid;
	}

}
